Skip to content

Update 'restart connection' action to reset internal state#19971

Open
carlos-zamora wants to merge 1 commit intomainfrom
dev/cazamor/restart-connection/reset-state
Open

Update 'restart connection' action to reset internal state#19971
carlos-zamora wants to merge 1 commit intomainfrom
dev/cazamor/restart-connection/reset-state

Conversation

@carlos-zamora
Copy link
Member

Summary of the Pull Request

I was becoming frustrated with getting in a state where a CLI app (i.e. Copilot CLI) enters some VT state (like mouse mode) then doesn't unset it when it accidentally exits. I normally use "Restart connection" to keep the buffer and connect again. Problem is, "restart connection" didn't actually reset the internal state! So I would type and get a bunch of lingering VT escape sequences.

Fixed that by updating the action to now also reset the VT state. Most of this PR is plumbing that through the layers. AdaptDispatch is where the real change actually happens:

  • added a _hardResetCore(bool) to be able to filter out the logic where the buffer is cleared (I don't want that part)
  • HardReset() --> _hardResetCore(true)
  • HardResetWithoutBufferClear() --> _hardResetCore(false)

I decided to add to the existing behavior rather than adding a new action or action arg. That said, I'm very open to making changes. Just let me know. 😊

Validation Steps Performed

  • Used this to enter mouse tracking mode: Write-Host -NoNewline "e[?1003he[?1006h"
  • mouse selection doesn't work as usual (expected)
  • invoke "restart connection" action
  • mouse selection works as usual

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm. I don't love how we have to send this all the way down through the RIS handler. However, it's also the only thing that knows the full gamut of things that need done to reset the terminal.

I'd love @j4james' opinion on the layering here.

If I had nits to pick, they would be:

ResetConnection should be named HardResetWithoutErase, clearBuffers should be named erase, BufferClear should be called Erase; later we can also add TermControl::HardReset which allows whoever's driving terminal to reset it with all the usual ceremony.

Also, why does TerminalCore need to reach into StateMachine? What state is stuck in stateMachine?

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Mar 17, 2026
@j4james
Copy link
Collaborator

j4james commented Mar 17, 2026

Yeah, I'm a little uncomfortable with this partial hard reset concept. If we were using either a plain hard reset, or a plain soft reset that would be fine. It may not be exactly what we want, but they're at least well-defined concepts. This feels like we're hacking in the things we want to reset for a single use case.

But maybe I'm being too picky. We had a similar discussion in PR #18437, which was never fully resolved. So I think we should at least try and make sure that what we're doing here is also going to work for that use case, so we can share the functionality if possible.

I'm also a little worried about how this is going to interact with the conhost state. If we're resetting Windows Terminal, but not resetting conhost, are they not going to end up out of sync now? Do we not have a way to pass that reset through somehow? This is maybe less of an issue with the new conpty, but it could still affect shells that rely on the legacy console APIs. I might be overthinking things though. If you're doing a reset, the terminal is assumedly messed up already, so an imperfect fix is probably better than nothing.

And assuming we do want to keep this HardResetWithoutBufferClear concept, my personal preference would be to drop the additional method, and just add the bool directly to the existing HardReset. But that's just a nitpick. It's fine as it is if you disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants